package bobaini.com.direct_exchange;

import bobaini.com.util.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * ClassName: Consumer
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/07/25-22:21:00
 * Description:
 */
public class Consumer01 {
    private static final String EXCHANGE_NAME = "direct_name_logs";

    private static final String QUEUE_NAME = "direct_name11";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        /**
         * 声明交换机
         */
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        /**
         * 声明队列
         */
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        /**
         * 队列和交换机进行绑定
         */
        channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "error");
        DeliverCallback deliverCallback = (s1, s2) -> {
            System.out.println("消费者消费队列C1的消息:" + new String(s2.getBody(), "UTF-8"));
        };
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> {
            System.out.println("取消回调该接口");
        });
    }
}
